/**
 * @lastUpdateBy : 韩怡婷
 * @description: JSON数据管理相关api
 */
import qs from "qs"; // 导入qs模块 增加了一些安全性的查询字符串解析和序列化字符串的库
export default {
  /**
   * @lastUpdateBy : 韩怡婷
   * @description: 获取json管理数据
   * @param {*} name 表名
   * @param {*} page=1&rows=1000 参数
   * @return {Promise}
   */
  getJsonStore(params) {
    return new Promise((resolve, reject) => {
      agcim.net.axiosWraper
        .getData(agcim.net.apiPath.io_jsonstore_getByDomainAndUsage, params)
        .then(
          (response) => {
            if (response.success) {
              resolve(response);
            } else {
              reject(response);
            }
          },
          (error) => {
            reject(error);
          }
        );
    });
  },
  /**
   * @lastUpdateBy : 韩怡婷
   * @description: 新增json管理数据
   * @param {*} params
   * @return {*}
   */
  saveJsonStore(params) {
    return new Promise((resolve, reject) => {
      agcim.net.axiosWraper
        .getDataByPost(
          agcim.net.apiPath.io_jsonstore_save,
          qs.stringify(params)
        )
        .then(
          (response) => {
            if (response.success) {
              resolve(response);
            } else {
              reject(response);
            }
          },
          (error) => {
            reject(error);
          }
        );
    });
  },
  /**
   * @lastUpdateBy : 韩怡婷
   * @description: 更新json管理数据
   * @param {*} params
   * @return {*}
   */
  updateJsonStore(params) {
    return new Promise((resolve, reject) => {
      agcim.net.axiosWraper
        .getDataByPost(
          agcim.net.apiPath.io_jsonstore_update,
          qs.stringify(params)
        )
        .then(
          (response) => {
            if (response.success) {
              resolve(response);
            } else {
              reject(response);
            }
          },
          (error) => {
            reject(error);
          }
        );
    });
  },
  deleteJsonStore(params) {
    return new Promise((resolve, reject) => {
      agcim.net.axiosWraper
        .getData(agcim.net.apiPath.io_jsonstore_deleteById, {
          params,
        })
        .then(
          (response) => {
            if (response.success) {
              resolve(response);
            } else {
              reject(response);
            }
          },
          (error) => {
            reject(error);
          }
        );
    });
  },
};
